fix rounding in holux.
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 20 Nov 2022 20:38:58 +0000 (13:38 -0700)
committertsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 20 Nov 2022 20:45:38 +0000 (13:45 -0700)
and fiddle with the make short default name so we can do a
roundtrip test.

holux.cc
testo.d/holux.test

index 0fed1e655018ca6a53d7d0dbab59d1cc6c12ce18..4d3c4ab81abc5dcc5a302a52e4444fef2dcbc7ad 100644 (file)
--- a/holux.cc
+++ b/holux.cc
@@ -25,15 +25,25 @@ History:
 */
 /* This module is for the holux (gm-100) .wpo format */
 
-#include "defs.h"
+#include <cstring>                 // for strncpy, memset, strcpy, strlen
+#include <cstdio>                  // for sprintf
+#include <ctime>                   // for gmtime, mktime, time_t, tm
+
+#include <QDate>                   // for QDate
+#include <QString>                 // for QString
+#include <QTime>                   // for QTime
+#include <QtGlobal>                // for qRound
+
+#include "defs.h"                  // for Waypoint, le_write16, le_write32
 #include "holux.h"
-//#include <math.h>
-#include <cstdio>
-#include <cstdlib>
+#include "gbfile.h"                // for gbfclose, gbfopen_le, gbfile, gbfread
+#include "src/core/datetime.h"     // for DateTime
 
-static  gbfile* file_in, *file_out;
-static         unsigned char* HxWFile;
-static  short_handle mkshort_handle;
+
+static gbfile* file_in;
+static gbfile* file_out;
+static unsigned char* HxWFile;
+static short_handle mkshort_handle;
 
 #define MYNAME "Holux"
 
@@ -149,7 +159,7 @@ static void data_read()
 
 static const char* mknshort(const char* stIn,unsigned int sLen)
 {
-#define MAX_STRINGLEN 255
+  constexpr int MAX_STRINGLEN = 255;
   static char strOut[MAX_STRINGLEN];
   char strTmp[MAX_STRINGLEN];
 
@@ -163,6 +173,7 @@ static const char* mknshort(const char* stIn,unsigned int sLen)
 
   setshort_length(mkshort_handle, sLen);
   setshort_mustuniq(mkshort_handle, 0);
+  setshort_defname(mkshort_handle, "");
 
   char* shortstr = mkshort(mkshort_handle, stIn, false);
   strcpy(strTmp,shortstr);
@@ -181,15 +192,6 @@ static void holux_disp(const Waypoint* wpt)
   double lon = wpt->longitude * 36000.0;
   double lat = wpt->latitude * -36000.0;
 
-
-  /* round it to increase the accuracy */
-  if (lon != 0) {
-    lon += (double)((int)lon/abs((int)lon)) * .5;
-  }
-  if (lat != 0) {
-    lat += (double)((int)lat/abs((int)lat)) * .5;
-  }
-
   short sIndex = le_read16(&((WPTHDR*)HxWFile)->num);
 
   if (sIndex >= MAXWPT) {
@@ -237,8 +239,8 @@ static void holux_disp(const Waypoint* wpt)
   // yield undefined results for negative values.
   // We intentionally convert to int, then do an implicit
   // conversion to unsigned in the call.
-  le_write32(&pWptHxTmp->pt.iLatitude,(signed int) lat);
-  le_write32(&pWptHxTmp->pt.iLongitude,(signed int) lon);
+  le_write32(&pWptHxTmp->pt.iLatitude, qRound(lat));
+  le_write32(&pWptHxTmp->pt.iLongitude, qRound(lon));
   pWptHxTmp->checked = 01;
   pWptHxTmp->vocidx = (short)0xffff;
   le_write16(&((WPTHDR*)HxWFile)->num, ++sIndex);
index 61e4627916d0cb609879988ca0afe5c7b4187b4a..4b30d1687f790cfae8e3099d8b6096b5f7513f63 100644 (file)
@@ -5,4 +5,4 @@
 # So we verify that we can read the reference and write it and get an
 # identical reference.
 gpsbabel -i holux -f ${REFERENCE}/paris.wpo -o holux -F ${TMPDIR}/paris.wpo
-compare ${REFERENCE}/paris.wpo ${TMPDIR}/paris.wpo
+bincompare ${REFERENCE}/paris.wpo ${TMPDIR}/paris.wpo